package com.atguigu.gmall.cart.service;

import com.atguigu.gmall.cart.mapper.CartMapper;
import com.atguigu.gmall.cart.pojo.Cart;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class AsyncCartService {
    @Resource
    private CartMapper cartMapper;
    @Async
    public void insertCart(String userId , Cart cart) {
        cartMapper.insert(cart);
    }
    @Async
    public void updateCart(String userId,Cart cart,  String skuId) {
        cartMapper.update(cart,new LambdaQueryWrapper<Cart>().eq(Cart::getSkuId, skuId).eq(Cart::getUserId, userId));
    }

    @Async
    public void deleteCart(String userKey) {
        cartMapper.delete(new LambdaQueryWrapper<Cart>().eq(Cart::getUserId,userKey));
    }

    @Async
    public void deleteBySkuId(String userId,Long skuId) {
        cartMapper.delete(new LambdaQueryWrapper<Cart>().eq(Cart::getSkuId,skuId).eq(Cart::getUserId,userId));
    }
}
